Add multiple assignment support to type inference#50
Merged
Conversation
Ruby's multiple assignment (e.g., `a, b = 1, "hello"`) is a common pattern that previously caused the type checker to skip variable registration entirely. This meant any subsequent use of variables assigned via multiple assignment would be untyped, leading to false negatives in method chain validation. This commit handles the ArrayNode RHS case where each literal value on the right-hand side is paired with its corresponding target on the left-hand side via zip. Non-ArrayNode RHS (single expression, method return decomposition) falls back to registering variables as untyped to prevent panics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
a, b = 1, "hello") in the type inference engineArrayNode(multiple literal values), each element is paired with its corresponding LHS target viazip, enabling correct per-variable type inferenceArrayNodeRHS (single expression, method return decomposition) registers variables as untyped to prevent panicsassignments.rsmodule follows the existingprocess_*_nodepatternTest plan
test_multi_write_integer_and_string—a, b = 1, "hello"→ a: Integer, b: Stringtest_multi_write_all_integer—a, b, c = 1, 2, 3→ all Integertest_multi_write_variable_reference_after_assignment—a, b = 1, "hello"; x = a→ x: Integertest_multi_write_lhs_longer_than_rhs—a, b, c = 1, 2→ zip skips c (known v0.1.8 limitation)test_multi_write_does_not_panic_on_non_array_rhs—a, b = some_expr→ no panic, variables registered as untyped🤖 Generated with Claude Code